// /////////////////////////////////////////////////////////////////////////////
// g3 group ////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////
$.fn.getG3data = function(_lotto_id,_gametype){
 $().disAreaObj();
 $.getJSON('op.php?op=xml_3d&fp=rate_3d&playtype=g3&lotto_id_3d='+_lotto_id+"&gametype="+_gametype+"&disk="+ $("select#slcDisk").val() ,function(ratedata){
      var dataLen = 0;
      var urlPre = "";
      var hrefStr = "";
      if(ratedata.errormsg != undefined){
        $("div#errormsg").addClass("error").text("No Rate data");
      }else{
          var disk = $("select#slcDisk").val();
          $().creatRateData(ratedata.r24, '24');
          $().creatRateData(ratedata.r25, '25');
          $().creatRateData(ratedata.r26, '26');
          $().creatRateData(ratedata.r27, '27');
          $().creatRateData(ratedata.r28, '28');
          $().creatRateDataTowFace(ratedata.r29, '29',_gametype,disk);
          $("div#errormsg").text("");
          $("div#mainPageData").show();
          
          // bind here for chinese word
          $(".sel").bind('click',function(){//tr>td>input:checkbox
		    var o=$(this).find("input");
			if(o.attr("checked",o.attr("checked")==false))
            o.showChkMsg();
          });;
          
      }
      $().redisAreaObj();
  });
};


// create table data
$.fn.creatRateData = function(rdata, rnum){
    var dataLen = rdata.number.length;
    var tbd = "tbody#tbdr"+rnum;
    $(tbd).empty();
    for(i = 0; i < dataLen; i++){
      classType = rdata.number[i].substr(0,1);    
      $('<tr class="td2" align=center><th class="gtdnum title02_3d">'+rdata.number[i]+'</th><td class="betnum"><span class="betRateNum">'+rdata.rates[i]+'</span></td><td class="sel"><input style="display:none" type="checkbox" size="3" value="'+rdata.number[i]+'" name="r'+rnum+'[]" /></td></tr>').appendTo(tbd);
    }
};

// create table data tow face
$.fn.creatRateDataTowFace = function(rdata, rnum,_gametype,disk){
    var dataLen = rdata.number.length;
    urlPre = "op.php?op=member_3d&fp=bet_fast&palygroup=g3&bettype="+rnum+"&gametype="+_gametype+"&disk="+disk;
    for(i = 0; i < dataLen; i++){
    hrefStr = urlPre + "&num=" + rdata.number[i] + "&rate=" + rdata.rates[i];
    $("tbody#tbdr"+rnum+" tr:nth-child(" +rdata.number[i] + ")>td:nth-child(2)").html('<a href="'+hrefStr+'" class=\"betRateNum\" target=\"leftFrame\">'+rdata.rates[i]+'</a>');}
  
};

// count how many groups
$.fn.countGroups = function(typenum, num){
  var reval = 0;
  
  if(typenum == num){ 
    return 1;
  }else{
    var cut = num - typenum;
    reval = 1;
    for(i = 0; i < cut; i++){
      reval *= (num - i);
    }
    return reval; 
  }

};